package com.principle.ocp.improve;

/**
 * @author 冯志立
 * @create 2019-10-15 16:22
 */
public class Ocp2 {
    public static void main(String[] args) {

    }
}

//用于绘图的类[使用方]
class GraphicEditor {
    //接受shape对象，根据type绘制图形
    public void drawShape(Shape s) {
        s.draw();
    }
}

//基类
abstract class Shape {
    int m_type;

    public abstract void draw(); //抽象方法
}

class Rectangle extends Shape {
    Rectangle() {
        super.m_type = 1;
    }

    @Override
    public void draw() {
        System.out.println("绘制矩形");

    }
}

class Circle extends Shape {
    Circle(){
        super.m_type = 2;
    }

    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}

class Triangle extends Shape{
    Triangle(){
        super.m_type = 3;
    }

    @Override
    public void draw() {
        System.out.println("绘制三角形");

    }
}

//新增一个图形

class OtherGraphic extends Shape{
    OtherGraphic(){
        super.m_type = 4;
    }

    @Override
    public void draw() {
        System.out.println("绘制一个其他图形");
    }
}